-
Notifications
You must be signed in to change notification settings - Fork 1.1k
GH-3902: Add Kotlin Coroutines Support #3905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This is one side of the medal. |
9eac6dc
to
1e62d21
Compare
That was fast! This is great news. As I'm not familiar with Spring Integration internals, it's not totally clear to me what your changes mean to me as an end user. Could you maybe provide some examples of how users can now leverage Kotlin suspending functions together with Spring Integration? |
See changes in the documentation in the end of this PR: https://github.com/spring-projects/spring-integration/pull/3905/files#diff-5c545e2b0af49eeeec3f6c017be8658b8e49f1f4a22e5e12310c41cf69f7407d |
.../main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java
Outdated
Show resolved
Hide resolved
Needs rebase (what's new). |
Fixes spring-projects#3902 * Add `isAsync()` propagation from the `MessagingMethodInvokerHelper` to the `AbstractMessageProducingHandler` to set into its `async` property. The logic is based on a `CompletableFuture`, `Publisher` or Kotlin `suspend` return types of the POJO method * Introduce `IntegrationMessageHandlerMethodFactory` and `IntegrationInvocableHandlerMethod` to extend the logic to newly introduced `ContinuationHandlerMethodArgumentResolver` and call for Kotlin suspend functions. * Remove `MessageHandlerMethodFactoryCreatingFactoryBean` since its logic now is covered with the `IntegrationMessageHandlerMethodFactory` * Kotlin suspend functions are essentially reactive, so use `CoroutinesUtils.invokeSuspendingFunction()` and existing logic in the `AbstractMessageProducingHandler` to deal with `Publisher` reply * Fix `GroovySplitterTests` for the current code base * Add `kotlinx.coroutines.flow.Flow` support The `Flow` is essentially a multi-value reactive `Publisher`, so use `ReactiveAdapterRegistry` to convert any custom reactive streams result to `Flux` and `Mono` which we already support as reply types * Add docs for `Kotlin Coroutines` Rearrange the doc a bit extracting Kotlin support to individual `kotlin-functions.adoc` file * Fix missed link to `reactive-streams.adoc` from the `index-single.adoc` * Fix unintended Javadocs formatting in the `AbstractMessageProducingHandler` * Add suspend functions support for Messaging Gateway * Add convenient `CoroutinesUtils` for Coroutines types and `Continuation` argument fulfilling via `Mono` * Treat `suspend fun` in the `GatewayProxyFactoryBean` as a `Mono` return * Convert `Mono` to the `Continuation` resuming in the end of gateway call * Document `suspend fun` for `@MessagingGateway`
* Mention default sync behavior in the docs
Co-authored-by: Gary Russell <[email protected]>
Fixes #3902
isAsync()
propagation from theMessagingMethodInvokerHelper
to theAbstractMessageProducingHandler
to set into itsasync
property. The logic is based on aCompletableFuture
,Publisher
or Kotlinsuspend
return types of the POJO methodIntegrationMessageHandlerMethodFactory
andIntegrationInvocableHandlerMethod
to extend the logic to newly introducedContinuationHandlerMethodArgumentResolver
and call for Kotlin suspend functions.MessageHandlerMethodFactoryCreatingFactoryBean
since its logic now is covered with theIntegrationMessageHandlerMethodFactory
CoroutinesUtils.invokeSuspendingFunction()
and existing logic in theAbstractMessageProducingHandler
to deal withPublisher
reply